package org.example.examsystem.service;

import org.example.examsystem.entity.StudentExam;
import org.example.examsystem.mapper.StudentExamMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class StudentExamServiceImpl implements StudentExamService {

    @Autowired
    private StudentExamMapper studentExamMapper;

    @Override
    public Page<StudentExam> getAnsweredExams(Pageable pageable) {
        int offset = pageable.getPageNumber() * pageable.getPageSize();
        int pageSize = pageable.getPageSize();
        List<StudentExam> studentExams = studentExamMapper.getAnsweredExams(offset, pageSize);
        int total = studentExamMapper.countAnsweredExams();
        return new PageImpl<>(studentExams, pageable, total);
    }
}